<template>
	<!-- 商品显示组件-横向排列方式显示 -->
	<view class="bg-white"
		:class="newData.background? newData.background.indexOf('bg-') != -1 ? newData.background : '': '' "
		:style="{paddingTop: `${newData.paddingT}rpx`,paddingBottom: `${newData.paddingB}rpx`,  paddingLeft: `${newData.pageSpacing}rpx`,
          paddingRight: `${newData.pageSpacing}rpx`, backgroundColor: newData.background ? newData.background.indexOf('bg-') !== -1 ? '' : newData.background : '',}">
		<view class="wrapper-list-goods"
			:style="{ borderRadius: `${newData.borderRadius}rpx`,background: newData.innerImg ? `url(${newData.innerImg})` : '', paddingTop: `${newData.innerPaddingTB}rpx`, 
          paddingBottom: `${newData.innerPaddingTB}rpx`,  paddingLeft: `${newData.innerPaddingLR}rpx`, paddingRight: `${newData.innerPaddingLR}rpx`, }">
			<view class="flex-row-between">
				<view class="text-bold" :style="{color: `${newData.titleColor}`,fontSize: `${newData.titleSize}rpx`}">
					{{ newData.title }}
				</view>
				<navigator hover-class="none" :url="newData.pageUrl" style="color: #8993A4;" v-if="newData.pageUrl">
					更多<text class="cuIcon-right"></text>
				</navigator>
			</view>
			<view>
				<scroll-view class="scroll-view_x goods-detail" scroll-x style="width:auto;">
					<block v-for="(item, index) in newData.goodsList" :key="index">
						<navigator hover-class="none" :url="'/pages/goods/goods-detail/index?id=' + item.id"
							class="item shadow-warp flex goods-box radius">
							<view @tap="click">
								<view class="img-box">
									<view class="p-relative h-100" v-if="item.prescription=='2'">
										<view class="flex-column-center w-100 h-100 font-24"
											style="position: absolute;z-index: 50;">
											<view class="">处方药依法不展示包装</view>
											<view class="">请在药师指导下使用</view>
										</view>
										<image
											:src="item.picUrls[0] ? item.picUrls[0] : '/static/public/img/no_pic.png'"
											class="image" style="filter: blur(5rpx);"></image>
									</view>
									<image :src="item.picUrls[0] ? item.picUrls[0] : '/static/public/img/no_pic.png'"
										class="image" v-if="item.prescription!='2'"></image>
								</view>
								<view class="text-cut margin-top-sm text-sm pLeft-10 text-bold mBtm-10"
									style="color: #1D2129;">
									{{item.name}}
								</view>
								<!-- 单sku -->
								<view class="flex align-center" v-if="(item.priceDown==item.priceUp)&&item.skus&&item.skus.length">
									<view class="text-price text-red text-lg text-bold"
										style="margin: 5rpx 10rpx;">
										<text>{{item.skus[0].salesPrice ? item.skus[0].salesPrice.toFixed(2) : '0.00'}}</text>
										<text class="text-price text-gray1 line-through mLeft-10 font-22"
											v-if="item.skus[0].marketPrice > item.skus[0].salesPrice">
											{{ item.skus[0].marketPrice ? item.skus[0].marketPrice.toFixed(2) : '0.00'}}
										</text>
									</view>									
								</view>
								<!-- 多sku -->
								<!-- <view class="text-price text-red margin-left-sm text-lg text-bold"
									style="margin: 5rpx 10rpx;" v-if="item.priceDown<item.priceUp">
									{{item.priceDown}}~{{item.priceUp}}
								</view> -->
								<view class="cfBox" v-if="item.prescription=='2'">处方药</view>
								<view class="preBox" v-if="item.isPressell == 1">预约</view>
							</view>
						</navigator>
					</block>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	import api from '@/utils/api'
	export default {
		components: {},
		props: {
			value: {
				type: Object,
				default: function() {
					return {
						title: '商品甄选',
						titleColor: 'red',
						titleIcon: 'cuIcon-message',
						pageSpacing: 0,
						goodsList: [],
					}
				}
			}
		},
		data() {
			return {
				theme: app.globalData.theme, //全局颜色变量
				newData: this.value,
			};
		},
		mounted() {
			this.getgoodsList()
		},
		methods: {
			click() {
				uni.$emit('newShopsList', '1')
			},
			jumpPage(page) {
				if (page) {
					uni.navigateTo({
						url: page
					});
				}
			},
			// 获取活动商品
			getgoodsList() {
				if (this.newData.goodsList && this.newData.goodsList.length > 0) {
					let goodsids = []
					this.newData.goodsList.forEach(v => {
						goodsids.push(v.id)
					})
					const goodsData = {
						ids: goodsids.toString()
					}
					api.getHomepageGoods(goodsData).then(res => {
						let data = res.data
						if (data.length > 0) {
							this.newData.goodsList = data.filter(v => {
								return v && v.shelf == '1'
							})
						} else {
							this.newData.goodsList = []
						}

					})
				}
			}
		}
	}
</script>

<style scoped>
	.wrapper-list-goods {
		white-space: nowrap;
		background-color: #fff;
		/* padding: 0 30rpx 6rpx 30rpx; */
		background-size: 100% 100% !important;
	}

	.wrapper-list-goods .item {
		display: inline-block;
		width: 260rpx;
		height: auto;
		margin-top: 10px;
		/* margin-bottom: 10px; */
		margin-left: 10rpx;
		margin-right: 10rpx;
		border: 1rpx solid #eee;
		background-color: #fff;
	}

	.wrapper-list-goods .item:first-child {
		margin-left: 0rpx;
	}

	.wrapper-list-goods .items {
		display: inline-block;
		width: 120;
		height: 340rpx;
		margin-top: 10px;
		margin-bottom: 10px;
		margin-left: 10rpx;
		margin-right: 10rpx;
		border: 1rpx solid #eee;
	}

	.wrapper-list-goods .item:nth-last-child(1) {
		margin-right: 0;
	}

	.wrapper-list-goods .item .img-box {
		width: 100%;
		height: 260rpx;

	}

	.wrapper-list-goods .item .img-box .image {
		width: 100%;
		height: 100%;
		border-radius: 5rpx 5rpx 0 0;
	}

	.goods-selection {
		margin-left: 0rpx !important;
		color: #666666;
	}

	.goods-more {
		margin-right: 0rpx !important;
		color: #666666;
	}

	.goods-box {
		width: 349rpx;
		/* height: 530rpx; */
		background-color: #fff;
		overflow: hidden;
		/* margin-bottom: 20rpx; */
		border-radius: 10rpx;
	}

	.goods-box .img-box {
		width: 100%;
		height: 349rpx;
		overflow: hidden;
	}

	.goods-box .img-box .image {
		width: 100%;
		height: 349rpx;
	}

	.goods-detail {
		/* margin-top:-20rpx !important; */
	}

	.goods-more {
		text-align: center;
		line-height: 340rpx;
		width: 130rpx;
		background: #ccc;
		color: #fff;
	}

	.cfBox {
		width: 100rpx;
		height: 40rpx;
		line-height: 40rpx;
		text-align: center;
		background-color: #00a6ba;
		position: absolute;
		left: 0;
		top: 0;
		color: white;
		border-radius: 10rpx;
	}

	.preBox {
		width: 260rpx;
		height: 40rpx;
		line-height: 40rpx;
		text-align: center;
		background-color: #F76164;
		position: absolute;
		left: 0;
		top: 220rpx;
		color: white;
		opacity: 0.8;
	}
</style>